package com.hissy.common.office.exporter;

import org.apache.commons.csv.CSVFormat;
import org.apache.commons.csv.CSVPrinter;

/**
 * Csv导出器
 */
public class CsvDataExporter implements DataExporter {

    StringBuilder out;
    CSVPrinter printer;

    public CsvDataExporter() throws Exception {
        out = new StringBuilder();
        printer = new CSVPrinter(out, CSVFormat.DEFAULT);
    }

    @Override
    public String getExtension() {
        return "csv";
    }

    @Override
    public void writeRow(String[] values) throws Exception {
        printer.printRecord(values);
    }

    @Override
    public byte[] getBytes() throws Exception {
        return out.toString().getBytes();
    }

}
